import pytest
import yaml


def load_test_data():
    with open('../data/test_data.yaml', 'r', encoding='utf-8') as file:
        data = yaml.safe_load(file)
    return data


def test_user_object():
    # 加载YAML数据
    data = load_test_data()

    # 获取user对象 (在Python中是一个字典)
    user = data['user']

    # 断言验证字典中的值
    assert user['name'] == "张三"
    assert user['age'] == 30
    assert user['is_active'] is True
    # 可以访问嵌套的对象
    assert user['address']['city'] == "北京"


# 使用pytest的参数化功能，直接从YAML中获取数据进行测试
@pytest.mark.parametrize('user_data', [load_test_data()['user']])
def test_user_with_parametrize(user_data):
    assert isinstance(user_data, dict)  # 验证它是字典
    assert 'name' in user_data